package com.zfzs.post.controller;

import com.zfzs.post.aop.log.Log;
import com.zfzs.post.common.bean.ResponseResult;
import com.zfzs.post.model.dto.TerminalTypeIdDTO;
import com.zfzs.post.modules.policy.domain.PolicyInfo;
import com.zfzs.post.modules.policy.service.PolicyInfoService;
import com.zfzs.post.service.PolicyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 政策设置
 *
 * @author: ck
 * @create: 2019/9/9/16:41
 **/
@Slf4j
@RestController
@RequestMapping("policy/")
public class PolicyController {

    @Autowired
    private PolicyService policyService;

    /**
     * 获取政策设置信息
     *
     * @return
     */
    @Log("获取政策设置信息")
    @PostMapping(value = "get_policy_info")
    public ResponseResult queryPolicyInfo(@Validated @RequestBody TerminalTypeIdDTO dto) {
        Map<String, Object> map = policyService.queryPolicyInfo(dto);
        return ResponseResult.ok(map);
    }

    /**
     * 是否可以设置政策
     */
    @Log("是否可以设置政策")
    @PostMapping(value = "is_setting_policy")
    public ResponseResult isSettingPolicy(@Validated @RequestBody TerminalTypeIdDTO dto) {
        Map<String, Object> map = policyService.isSettingPolicy(dto);
        return ResponseResult.ok(map);
    }

    /**
     * 设置政策信息
     *
     * @param policyInfo 设置信息
     * @return
     */
    @Log("设置政策信息")
    @PostMapping(value = "set_policy_info")
    public ResponseResult setPolicyInfo(@Validated @RequestBody PolicyInfo policyInfo) {
        policyService.setPolicyInfo(policyInfo);
        return ResponseResult.okMsg("政策设置成功");
    }
}
